import React, { useEffect, useState } from "react";
import { Input } from "@/views/components/PrefixPlaceholder";
import TagModal from "./TagModal";
const SelectOrderTag = ({ value = { isLabelOr: true }, onChange }) => {
	const [includeTagModalVisible, setIncludeTagModalVisible] = useState(false);
	const [includeTagText, setIncludeTagText] = useState("");
	const [includeTag, setIncludeTag] = useState("");

	const triggerChange = changedValue => {
		onChange?.({ ...value, ...changedValue });
	};

	const handleIncludeTagChange = value => {
		console.log(value, "value");
		setIncludeTag(value);
		triggerChange(value);
	};
	useEffect(() => {
		setIncludeTagText(value.includeTagText);
	}, [value.includeTagText]);

	return (
		<>
			<Input value={includeTagText} data={includeTag} placeholder="商品标签" onClick={() => setIncludeTagModalVisible(true)} />
			<TagModal
				value={value}
				visible={includeTagModalVisible}
				onVisibleChange={setIncludeTagModalVisible}
				onChange={handleIncludeTagChange}
			/>
		</>
	);
};
export default SelectOrderTag;
